import React from 'react';
import {Form, Row, Col, Button, DatePicker, message ,Divider,Input,InputNumber ,Radio } from 'antd';
import { Link } from 'react-router-dom'
import {sessionManager} from '../../utils/sessionStorage';
import SCModal from '../../components/pickCity/SCModal'
import {injectIntl} from 'react-intl';
import Grid from '../../components/table/grid';
import axios from 'axios';

const FormItem = Form.Item;
const createForm = Form.create;
const RadioGroup = Radio.Group;

class stub extends React.Component {
    constructor(props) {
        super(props);
        this.common = this.props.intl.messages.common;
        this.columns = [
            {
                title: '名称',
                dataIndex: 'name',
                key: 'name',
            },
            {
                title: '地址',
                dataIndex: 'address',
                key: 'address',
            },
            {
                title: '操作',
                key: 'action',
                render: (text, record) => (
                    <span>
                        <a onClick={() => this.goLink(text, record, 'remove')}>移除</a>
                        <Divider type="vertical"/>
                        <a onClick={() => this.goLink(text, record, 'rules')}>分账规则</a>
                    </span>

                )
            }
        ];
        this.state = {
            refresh:0,
            visible:false,
            params:{
                companyId:sessionManager.get('companyInfo').id
            }
        }
    }

    componentDidMount(){
        
    }

    onChange = (e) => {
        console.log('radio checked', e.target.value);
        this.setState({
          value: e.target.value,
        });
      }



    goLink = (text, record, link) => {
        // sessionManager.set('BillInfo', text);
        switch (link) {
            case 'remove':
                break;
            case 'rules':
                axios.post('/api/stubGroup/billSplit/qry',{stubGroupId:text.id}).then(res=>{
                    if(res&&res.data){
                        this.setState({
                            visible: true,
                        });
                    }
                })
                break;
            default:
                console.log('adjust');
        }
    };


    render() {
        const formItemLayout = {
            labelCol: {
              xl: { span: 6 },
            },
            wrapperCol: {
              xl: { span: 6 },
            },
          };
          const formItemLayout2 = {
            labelCol: {
              xl: { span: 6 },
            },
            wrapperCol: {
              xl: { span: 12 },
            },
          };
          const {getFieldDecorator} = this.props.form;
        return (
            <div>
                <Grid params={this.state.params} url="/api/stubGroup/companyBindList" columns={this.columns} refresh={this.state.refresh}/>
                {/*  分账规则 */}
                <SCModal visible={this.state.visible} handleCancel={()=>{this.setState({visible:false})}} title={'分账规则'}>
                    <form form={this.props.form}>
                    <Row>
                        <Col span={18}>
                            <FormItem
                            {...formItemLayout}
                            label={"按固定金额"}
                            >
                                {getFieldDecorator('account',{
                                    rules: [
                                        {
                                            required: true,
                                            message: '改项为必填项'
                                        }, {
                                            validator: this.validatePhone
                                        }
                                    ]
                                })(
                                    <InputNumber />
                                )}
                            </FormItem>
                        </Col>
                        <Col>
                            <RadioGroup onChange={this.onChange} value={this.state.value}>
                                <Radio value={1}>A</Radio>
                            </RadioGroup>
                        </Col>
                    </Row>
                        
                        <FormItem
                        {...formItemLayout}
                        label={"按百分比"}
                        >
                            {getFieldDecorator('account',{
                                rules: [
                                    {
                                        required: true,
                                        message: '改项为必填项'
                                    }, {
                                        validator: this.validatePhone
                                    }
                                ]
                            })(
                                <InputNumber />
                            )}
                        </FormItem>
                    </form>
                </SCModal>

            </div>
        )
    }
}

stub = createForm()(stub);
export default injectIntl(stub)
